<template>
  <button ref="backRef" :class="row.selected ? 'selected' : ''">
    <el-tooltip placement="top" :show-after="200">
      <template #content>{{ row.title }}</template
      >
      <font-awesome-icon style="outline: 0" :icon="['fa', row.icon]" />
    </el-tooltip>
  </button>
</template>
<script lang="ts" >
import { getCurrentInstance, onMounted, reactive, ref ,defineComponent,toRefs, watchEffect } from "vue";
import { EditorContent, useEditor } from "@tiptap/vue-3";
import Pickr from "@simonwep/pickr";
import "@simonwep/pickr/dist/themes/monolith.min.css";

export default defineComponent({
  props: {
    row: {
      type: Object,
      default: () => {},
    },
    editor: {
      type: Object,
      default: () => {},
    },
  },
  name: "backColor",
  components: { EditorContent },
  setup(props, { emit }) {
    const state = reactive({
      color: "",
      picker: null,
    });
    const { proxy } = getCurrentInstance() as any;

    onMounted(() => {
      // 创建颜色选择器
      state.picker = new Pickr({
        el: proxy.$refs.backRef,
        theme: "monolith",
        useAsButton: true,
        swatches: ["#ffffff","#F44336", "#E91E63", "#9C27B0", "#673AB7"],
        components: {
          preview: true,
          hue: true,
          interaction: {
            input: true,
            save: true,
          },
        },
        i18n: { "btn:save": "确认" },
      });

      // 保存颜色设置
      state.picker.on("save", (color, instance) => {
        instance.hide();
        const hexValue = color.toHEXA().toString();
        console.log("字体颜色=============", hexValue);
        state.color = hexValue;
        //debugger
        props.editor.commands.toggleHighlight({ color: hexValue });
      });




    });

    return {
      ...toRefs(state),
    };
  },
});
</script>
<style scoped lang="less">
.editor-box {
  height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;

  &-head {
    background: #ffffff !important;
    padding: 0px 24px;
    color: #000000e0;
    font-size: 20px !important;
    height: 50px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    border-bottom: solid 1px #f0f3f5;

    button {
      font-size: 20px !important;
      padding: 5px 8px;
      color: #666666;
      border: 0;
      margin-right: 10px;
      background: transparent;
      cursor: pointer;
    }
  }

  &-content {
    flex: 1;
    padding: 0px 15px;
    overflow: auto;
    background-color: #ffffff;
  }
}

.selected {
  background: #f4f6f7 !important;
}
</style>
<style lang="less" >
/* 公众号文档样式 */
.tiptap.ProseMirror {
  min-height: 100%;
  outline: none;
  color: rgba(0, 0, 0, 0.9);
  font-size: 14px;
  line-height: 1.5;
  text-align: justify;
  padding: 20px 15px;
}

.ProseMirror * {
  max-width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box !important;
  word-wrap: break-word !important;
}

.ProseMirror p {
  /*clear: both;*/
  min-height: 1em;
}

.ProseMirror > p {
  margin-top: 0;
  /*margin-bottom: 16px;*/
}

.ProseMirror ul,
ol {
  list-style: disc;
}

.list-paddingleft-1 {
  padding-left: 1.2em;
}

.ProseMirror .code-snippet {
  margin: 10px 0;
  display: block;
  overflow-x: auto;
  font-size: 14px;
  padding: 1em 1em 1em 3em;
  color: #333;
  position: relative;
  background-color: #fafafa;
  border: 1px solid #f0f0f0;
  border-radius: 2px;
  counter-reset: line;
  white-space: normal;
  -webkit-overflow-scrolling: touch;
}

.ProseMirror .code-snippet code {
  display: flex;
  position: relative;
  text-align: left;
  white-space: pre;
  font-size: 14px;
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

.ProseMirror img.ProseMirror-separator {
  width: 0 !important;
}

.ProseMirror .video_iframe {
  background-color: #000000;
  width: 100% !important;
  position: static;
}

.ProseMirror a {
  color: #576b95;
  text-decoration: none;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/*.ProseMirror .h5_image_link,*/
/*.ProseMirror .weapp_image_link {*/
/*  position: relative;*/
/*  display: inline-block;*/
/*  font-size: 0;*/
/*}*/

/*.ProseMirror .h5_image_link::after {*/
/*  content: " ";*/
/*  display: block;*/
/*  position: absolute;*/
/*  top: 9px;*/
/*  right: 9px;*/
/*  width: 26px;*/
/*  height: 26px;*/
/*  background: url("@/assets/images/icon/icon-image-link.png") no-repeat center;*/
/*  background-size: contain;*/
/*}*/

/*.ProseMirror .weapp_image_link::after {*/
/*  content: " ";*/
/*  display: block;*/
/*  position: absolute;*/
/*  top: 9px;*/
/*  right: 9px;*/
/*  width: 26px;*/
/*  height: 26px;*/
/*  background: url("@/assets/images/icon/icon-weapp-link.png") no-repeat center;*/
/*  background-size: contain;*/
/*}*/
</style>